function loadHots(pageNum){
    let keyword = $("#keyword").val();
    $.ajax({
        url:"/hot/list",
        data:{keyword,pageNum:pageNum == null ? 1 : pageNum},
        type:"get",
        dataType:"json",
        success:function(result){
            //获取table中下标大于0的tr,然后删除
            $("#table tr:gt(0)").remove();
            result.list.forEach(hot=>{
                let $tr = $(`<tr align="center">
                                <td>${hot.keyword}</td>
                                <td>${hot.searchSum}</td>
                                <td>${hot.createDate}</td>
                            </tr>`);
                $("#table").append($tr);
            });
            console.log(result);
            let $page = $("#page");
            $page.html("");

            if (result.hasPreviousPage){
                let $first = $(`<a href="javascript:loadHots(1)">首页</a>`);
                let $prev = $(`<a href="javascript:void(0)" onclick="loadHots(${result.prePage})">上一页</a>`);
                $page.append($first);
                $page.append($prev);
            }
            if (result.hasNextPage){
                let $next = $(`<a href="javascript:void(0)" onclick="loadHots(${result.nextPage})">下一页</a>`);
                let $last = $(`<a href="javascript:void(0)" onclick="loadHots(${result.pages})">末页</a>`);
                $page.append($next);
                $page.append($last);
            }

            let $text = $(`<span>第${result.pageNum}页/共${result.pages}页</span>`);
            $page.append($text);
            $page.find("a").css("margin","0px 10px");

        }
    })
}

$(function(){
    loadHots(1);
})
